from pyDes import des, ECB, PAD_PKCS5
import base64

"""python pyDes ecb模式带k加密"""
Key = "xxxxxxx"[0:8]


# 加密
def encrypt_str(data):
    # 加密方法
    method = des(Key, ECB, padmode=PAD_PKCS5)
    # 执行加密码
    k = method.encrypt(data)
    # 转base64编码并返回
    return base64.b64encode(k)


# 解密
def decrypt_str(data):
    method = des(Key, ECB, padmode=PAD_PKCS5)
    # 对base64编码解码
    k = base64.b64decode(data)
    # 再执行Des解密并返回
    return method.decrypt(k)

# Encrypt = encrypt_str("Lian36289*")
# print(Encrypt)
# print(type(Encrypt))
# Decrypt = decrypt_str(Encrypt)
# print(Decrypt)
